package com.tangchao.client.sdh.view.jiaoFen
{
	import com.tangchao.client.sdh.definition.DFGetCard;
	import com.tangchao.client.sdh.event.JiaoFenEvent;
	
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.ui.Mouse;
	import flash.ui.MouseCursor;

	public class JiaoFenCell extends MovieClip
	{
		private var _mc:MovieClip;
		private var _num:int;
		private var _canClick:Boolean = false;
		private var _tfNum:TextField;
		
		public function JiaoFenCell()
		{
			mcBack.gotoAndStop(1);
			_mc=new MovieClip();
			addChild(_mc);
			
			_tfNum = getChildByName("tfNum") as TextField;
			
			mcBack.gotoAndStop(4);
			addEventListener(MouseEvent.MOUSE_OVER,onMouseOver);
			addEventListener(MouseEvent.MOUSE_OUT,onMouseOut);
			addEventListener(MouseEvent.CLICK, onSelect);
			addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
			addEventListener(MouseEvent.MOUSE_OUT, onMouseUp);
		}
		
		private function onMouseDown(e:MouseEvent):void
		{
			if(_canClick)
			{
				mcBack.gotoAndStop(3);
			}
		}
		
		private function onMouseUp(e:MouseEvent):void
		{
			if(_canClick)
			{
				mcBack.gotoAndStop(1);
			}
		}
		
		private function onMouseOver(e:MouseEvent):void
		{
			if(_canClick)
			{
				mcBack.gotoAndStop(2);
				Mouse.cursor = MouseCursor.BUTTON;
			}
		}
		
		private function onMouseOut(e:MouseEvent):void
		{
			if(_canClick)
			{
				mcBack.gotoAndStop(1);
				Mouse.cursor = MouseCursor.AUTO;
			}
		}
		
		private function onSelect(e:MouseEvent):void
		{
			if(_canClick)
			{
				var evt:JiaoFenEvent = new JiaoFenEvent();
				evt.isJiao=true;
				evt.value=num;
				dispatchEvent(evt);
			}
		}
		
		public function set canSelect(canSelect:Boolean):void
		{
			_canClick = canSelect;
			if(_canClick)
			{
				mcBack.gotoAndStop(1);
			}
			else
			{
				mcBack.gotoAndStop(4);
			}
		}
		
		public function set num(value:int)
		{
			_num = value;
			_tfNum.text = value.toString();
//			_num=value;
//			var vtos:String=value.toString();
//			for(var i:int=0;i<vtos.length;i++)
//			{
//				var mc:MovieClip=DFGetCard.getNumByNum(int(vtos.substr(i,1)));
//				_mc.addChild(mc);
//				_mc.gotoAndStop(5);
//				mc.x=mc.width/2*i;				
//			}
//			_mc.x = (this.width-_mc.width)/2;
//			_mc.y = (this.height-_mc.height)/2;
		}
		
		public function get num():int
		{
			return _num;
		}
		
		public function selectState(i:int)
		{
			mcBack.gotoAndStop(i);
		}
	}
}